#!/usr/bin/env python3
"""
创建雷达仿真智能体程序图标
支持PNG和ICO格式，多种尺寸
"""

try:
    from PIL import Image, ImageDraw
    import os

    def create_radar_icon():
        """创建雷达图标"""
        # 创建256x256的图像
        size = 256
        img = Image.new('RGBA', (size, size), (0, 0, 0, 0))
        draw = ImageDraw.Draw(img)

        center = size // 2

        # 背景圆形
        draw.ellipse([8, 8, size-8, size-8], fill=(13, 17, 23, 255), outline=(48, 54, 61, 255), width=3)

        # 雷达扫描圆环
        radii = [100, 75, 50, 25]
        for i, radius in enumerate(radii):
            alpha = 150 - i * 30
            draw.ellipse([center-radius, center-radius, center+radius, center+radius],
                        outline=(31, 111, 235, alpha), width=2)

        # 雷达扫描线
        line_color = (88, 166, 255, 255)
        line_width = 2
        draw.line([center, 28, center, 228], fill=line_color, width=line_width)  # 垂直线
        draw.line([28, center, 228, center], fill=line_color, width=line_width)  # 水平线

        # 目标点
        targets = [
            (165, 85, (253, 126, 20, 255)),   # 橙色目标
            (95, 160, (46, 160, 67, 255)),    # 绿色目标
            (180, 170, (248, 81, 73, 255))    # 红色目标
        ]

        for x, y, color in targets:
            draw.ellipse([x-4, y-4, x+4, y+4], fill=color)

        # 中心点
        draw.ellipse([center-5, center-5, center+5, center+5], fill=(88, 166, 255, 255))

        # 外边框装饰
        draw.ellipse([13, 13, size-13, size-13], outline=(88, 166, 255, 200), width=1)

        return img

    def save_icons():
        """保存多种格式的图标"""
        icon_dir = "icons"
        if not os.path.exists(icon_dir):
            os.makedirs(icon_dir)

        # 创建基础图标
        base_icon = create_radar_icon()

        # 保存PNG格式 - 多种尺寸
        sizes = [16, 32, 48, 64, 128, 256]
        png_files = []

        for size in sizes:
            resized = base_icon.resize((size, size), Image.Resampling.LANCZOS)
            png_path = os.path.join(icon_dir, f"radar_icon_{size}x{size}.png")
            resized.save(png_path, "PNG")
            png_files.append(png_path)
            print(f"Created: {png_path}")

        # 保存主PNG
        main_png = os.path.join(icon_dir, "radar_icon.png")
        base_icon.save(main_png, "PNG")
        print(f"Created: {main_png}")

        # 创建ICO文件 (包含多种尺寸)
        ico_path = os.path.join(icon_dir, "radar_icon.ico")
        ico_images = []
        for size in [16, 32, 48, 64, 128, 256]:
            ico_images.append(base_icon.resize((size, size), Image.Resampling.LANCZOS))

        ico_images[0].save(ico_path, format='ICO', sizes=[(s, s) for s in [16, 32, 48, 64, 128, 256]])
        print(f"Created: {ico_path}")

        return main_png, ico_path

    if __name__ == "__main__":
        png_path, ico_path = save_icons()
        print(f"\n✅ 雷达仿真智能体图标创建完成!")
        print(f"PNG格式: {png_path}")
        print(f"ICO格式: {ico_path}")
        print("\n图标特点:")
        print("- 256x256像素高清图标")
        print("- 深蓝色科技风格主题")
        print("- 雷达扫描动画效果设计")
        print("- 包含目标检测点")
        print("- 支持PNG和ICO多种格式")
        print("- 适用于Windows程序图标")

except ImportError as e:
    print(f"缺少必要库: {e}")
    print("请安装: pip install Pillow")
except Exception as e:
    print(f"创建图标时出错: {e}")